<%@ page language="java" contentType="text/html;charset=utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en" class="no-js">
<!--<![endif]-->
<head>
    <jsp:include page="../common/common.jsp"/>
</head>

<body class="page-header-fixed">
<jsp:include page="../common/header.jsp"/>
<div class="clearfix">
</div>
<div class="page-container">
    <div class="page-sidebar-wrapper"><jsp:include page="../common/menu.jsp"/></div>
    <div class="page-content-wrapper">
        <div class="page-content">
            <div class="row">
                <div class="col-md-12">                                    
                    <form class="form-horizontal form-row-seperated" id="form" method="post" action="${path}/mall/save">
                        <div class="portlet box purple">
                        
                            <div class="portlet-title">
                                <div class="caption">
                                    <i class="fa fa-shopping-cart"></i>详细内容
                                </div>
                                <div class="actions btn-set">
                                    <a href="javascript:history.go(-1);" class="btn default"><i
                                            class="fa fa-angle-left"></i> 返回</a>
                                    <a href="javascript:location.reload();" class="btn green"><i
                                            class="fa fa-reply"></i> 重置</a>
                                    <button type="button" onclick="save()" class="btn blue"><i class="fa fa-check"></i> 保存
                                    </button>
                                   
                                </div>
                            </div>
                            
                            <div class="portlet-body">                        
                                <div class="tabbable">
                                	<ul class="nav nav-tabs" id="table">
										<li class="active">
											<a href="#tab_general" data-toggle="tab">
												文字信息
											</a>
										</li>
										<li>
											<a href="#tab_images" data-toggle="tab">
												 图片信息
											</a>
										</li>
									</ul>
                                
                                    <div class="tab-content no-space">
                                        <div class="tab-pane active" id="tab_general">
                                            <div class="form-body">
                                              
                                                <div class="form-group" >
                                                  <label class="col-md-1 control-label">店名:
                                                    <span class="required">*</span>
			                                        </label>
			                                        <div class="col-md-2">
			                                            <input type="text" id="name" name="name" class="form-control" value="${data.name}"/>
			                                        </div>  
                                                    <label class="col-md-1 control-label">电话:
                                                      <span class="required">*</span>
                                                    </label>
                                                    
			                                        <div class="col-md-2">
			                                            <input type="text" id="tel" name="tel" class="form-control" value="${data.tel}"/>   
			                                        </div>	
                                                    <label class="col-md-1 control-label">简介:</label>
			                                        <div class="col-md-2">
			                                            <input type="text" id="ontime" name="brief" class="form-control" value="${data.brief}"/>  
			                                        </div>                                                   
                                                </div>
                                                
                                                  <div class="form-group">
                                                    <label class="col-md-1 control-label">地区:
                                                        <span class="required">*</span>
                                                    </label>
                                                    <div class="col-md-2">
                                                        <select id="province" name="province" class="form-control"></select>
                                                    </div>
                                                    <div class="col-md-3">
                                                        <select id="city" name="city" class="form-control"></select>
                                                    </div>
                                                    <div class="col-md-3">
                                                        <select id="county" name="county" class="form-control"></select>
                                                    </div>
                                                </div>                                                                                         
                                                <div class="form-group">
                                                
			                                        <label class="col-md-1 control-label">地址: 
			                                          <span class="required">*</span>
			                                         </label>
			                                        <div class="col-md-5" style="width: 450px">
			                                            <input type="text" id="address" name="address" class="form-control" value="${data.address}"/>  
			                                        </div>    
                                                	<label class="col-md-1 control-label">坐标:</label>
			                                        <div class="col-md-2">
			                                            <input type="text" id="lng" name="lng" class="form-control" value="${data.lng}"/>  
			                                        </div>
			                                       		 <a href="http://api.map.baidu.com/lbsapi/getpoint/"   target="_Blank">获取经纬度</a>                                      		                                     
                                                </div>
                                                
                                                  
                                                  <div class="form-group">
                                                    <label class="col-md-2 control-label">是否纯商家:
                                                    <span class="required">*</span>
                                                    </label>
																
                                                    <div class="col-md-2">
                                                              <select name="istype" class="form-control"  onchange="opemrte(this)">
                                                            <option value="1" <c:if test="${1== data.istype }">selected="selected" </c:if> >否</option>
                                                        	<option value="2" <c:if test="${2== data.istype }">selected="selected" </c:if> >是</option>
                                                        </select>
                                                    </div>
                                                    
                                              
                                        
                                                </div>
                                                
                                                
                                                    <div class="form-group"  id="dkea">
                                                    <label class="col-md-2 control-label">月浮动奖励利率 :
                                                    <span class="required">*</span>
                                                    </label>

                                                    <div class="col-md-2">
                                                        <input id="fdjlday" name="fdjlday" type="text"
                                                               class="form-control tags medium"
                                                               value="${data.fdjlday}"/>
                                                    </div>
                                            
                                                    
                                                      <label class="col-md-2 control-label">  季浮动奖励利率 : 
                                                    <span class="required">*</span>
                                                    </label>

                                                    <div class="col-md-2">
                                                        <input id="fdjljd" name="fdjljd" type="text"
                                                               class="form-control tags medium"
                                                               value="${data.fdjljd}"/>
                                                    </div> 
                                                      <label class="col-md-2 control-label">年浮动奖励利率  :
                                                    <span class="required">*</span>
                                                    </label>

                                                    <div class="col-md-2">
                                                        <input id="fdjlyear" name="fdjlyear" type="text"
                                                               class="form-control tags medium"
                                                               value="${data.fdjlyear}"/>
                                                    </div>
                                                </div>
                                                
                                                <div  class="form-group">
												<label class="col-md-1 control-label">logo</label>
												<div class="col-md-8">
												  <div class="fileinput fileinput-new" data-provides="fileinput">
                                                            <div class="fileinput-new thumbnail"
                                                                 style="width: 300px; height: 150px;">
                                                                <img src="${data.logo}" class="logo">
                                                            </div>
                                                            <div class="fileinput-preview fileinput-exists thumbnail"
                                                                 style="max-width: 300px; max-height: 150px;">
                                                            </div>
                                                            <div>
                                                                <span class="btn default btn-file">
                                                                    <span class="fileinput-new">选择图片</span>
                                                                    <span class="fileinput-exists">修改图片</span>
                                                                    <input type="file" id="file" name="file"/>
                                                                </span>
                                                                    &nbsp;&nbsp;&nbsp;
                                                              		<a onclick="delpic('logo');" class="btn default fileinput-new" data-dismiss="fileinput">删除</a>
                                                                <a href="#" class="btn default fileinput-exists" data-dismiss="fileinput">删除</a>
                                                      
                                                            </div>
                                                        </div>
												</div>
											</div>
											<div  class="form-group">
												<label class="col-md-1 control-label">活动图</label>
												<div class="col-md-5">
												  <div class="fileinput fileinput-new" data-provides="fileinput">
                                                            <div class="fileinput-new thumbnail"
                                                                 style="width: 300px; height: 150px;">
                                                                <img src="${data.by1}"  class="by1">
                                                            </div>
                                                            <div class="fileinput-preview fileinput-exists thumbnail"
                                                                 style="max-width: 300px; max-height: 150px;">
                                                            </div>
                                                            <div>
                                                                <span class="btn default btn-file">
                                                                    <span class="fileinput-new">选择图片</span>
                                                                    <span class="fileinput-exists">修改图片</span>
                                                                    <input type="file" id="filehd" name="filehd"/>
                                                                </span>
                                                                  &nbsp;&nbsp;&nbsp;
                                                              		<a onclick="delpic('by1');" class="btn default fileinput-new" data-dismiss="fileinput">删除</a>
                                                                <a href="#" class="btn default fileinput-exists" data-dismiss="fileinput">删除</a>
                                                            </div>
                                                        </div>
												</div>
												 	<label class="col-md-1 control-label">链接:</label>
			                                        <div class="col-md-2">
			                                            <input type="text" id="by2" name="by2" class="form-control" value="${data.by2}"/>  
			                                        </div>
										</div>
                                                                                  
	                                            <div class="form-group">
	                                                <label class="col-md-1 control-label">内容:
	                                                <span class="required">*</span>
	                                                </label>
	
	                                                <div class="col-md-8">
	                                                    <input id="context" type="hidden" name="introduce">
	                                                    <script id="editor" type="text/plain"
	                                                            style="height:500px;">${data.introduce}</script>
	                                                </div>
	                                            </div>
	                                            
	                                       
	                                      </div>                                                   
                                        </div>
                                        <div class="tab-pane" id="tab_images"><!-- 图片div- -->
                                         
	                                           <div id="tab_images_uploader_container" class="text-align-reverse margin-bottom-10">
												<a id="tab_images_uploader_pickfiles" href="javascript:;" onClick="upImage()" class="btn yellow">
													<i class="fa fa-plus"></i> 上传图片
												</a>
												</div>
											
    											 
    											 
    												<div id="imgshow"></div>
										</div>
                                    </div>
                                </div>
                            </div>
			 <script id="ueditorupload" type="text/plain"
	                                                            style="height:5px;display:none;" ></script>
                            <div class="portlet-title">
                                <div class="actions btn-set">
                                    <a href="javascript:history.go(-1);" class="btn default"><i
                                            class="fa fa-angle-left"></i> 返回</a>
                                    <a href="javascript:location.reload();" class="btn green"><i
                                            class="fa fa-reply"></i> 重置</a>
                                    <button type="button" onclick="save()" class="btn blue"><i class="fa fa-check"></i> 保存
                                    </button>
                                </div>
                            </div>
                        </div>
                                     <input type="hidden" id="organid" name="organid" value="${data.organid}">
                                     
                                     
         			 <input type="hidden" id="createTime" name="createTime" value="${data.createTime}">
                        <input type="hidden" id="id" name="id" value="${data.id}">
                        <input type="hidden" id="userid" name="userid" value="${data.userid}">
                      	<input type="hidden" id="logo" name="logo"  value="${data.logo}"/>       
                      	<input type="hidden" id="by1" name="by1"  value="${data.by1}"/>      
                      	<input type="hidden" id="mallimg" name="mallimg"  value="${data.mallimg}"/>  
                       	<input type="hidden" id="status" name="status"  value="${data.status}"/>  <!-- 现在默认都审核通过 -->
                       	<input type="hidden" id="userName" name="userName"  value="${data.userName}"/>       
                      	<input type="hidden" id="password" name="password"  value="${data.password}"/>      
                      	<input type="hidden" id="phone" name="phone"  value="${data.phone}"/>  
                       	<input type="hidden" id="contacts" name="contacts"  value="${data.contacts}"/>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<jsp:include page="../common/footer.jsp"/>
<script src="${path}/assets/plugins/jquery-migrate-1.2.1.min.js" type="text/javascript"></script>
<script type="text/javascript" src="${path}/assets/plugins/bootstrap-fileinput/bootstrap-fileinput.js"></script>

<script type="text/javascript" src="${path}/assets/plugins/jquery-inputmask/jquery.inputmask.bundle.min.js"></script>
<script type="text/javascript" src="${path}/assets/plugins/jquery.input-ip-address-control-1.0.min.js"></script>
<script type="text/javascript" src="${path}/assets/plugins/jquery.pwstrength.bootstrap/src/pwstrength.js"></script>
<script type="text/javascript" src="${path}/assets/scripts/custom/components-form-tools.js"></script>
<script type="text/javascript" src="${path}/assets/scripts/biz/ajaxfileupload.js"></script>
<script type="text/javascript" src="${path}/assets/plugins/ueditor/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" src="${path}/assets/plugins/district/linkagesel-min.js"></script>
<script  type="text/javascript" src="${path}/assets/plugins/ueditor/ueditor.config.js"></script>
<script  type="text/javascript" src="${path}/assets/plugins/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" src="${path}/assets/scripts/biz/jsAddress.js"></script>
<script type="text/javascript" src="${path}/mall/js/mallDetail.js"></script>            

  
<script>
    var operType = '${operType}';
    var editor, form,o_ueditorupload;

    $(function() {
    	//类型选择 分类
    	   $('#pid').change(function() {
               changeSecondType(this.value);
           });
           changeSecondType($('#pid').val());
           function changeSecondType(pid) {
               $.ajax({
                   url: _path + '/conf/queryConfTByPid?pid='+pid,
                   type: 'GET',
                   success: function(resp) {
                       $("#columnId").html('');
                       new LinkageSel({
                           dataReader: {id: 'id', name: 'value0'},
                           data: resp.dataList,
                           selStyle: 'margin-left: 3px;',
                           select:  '#columnId',
                           defVal: ['${data.columnId}']
                       });
                   }
               });
           }
    	//富文本框
   	   o_ueditorupload = UE.getEditor('ueditorupload', {
		        autoHeightEnabled:false,
		        catchRemoteImageEnable:false
		      });
		o_ueditorupload.ready(function ()  {
	//	o_ueditorupload.hide();//隐藏编辑器
	  //监听图片上传功能
	  	o_ueditorupload.addListener('beforeInsertImage', function (t,arg){
		var srm="";
		for(var i in arg){
			$('#imgshow').append("<div class='imgs' sr='"+arg[i].src+"' ><img height=180' width='180'  src='"+arg[i].src+"'/><a  href='#' el='"+arg[i].src+"'  class='xle' onClick='dels(this)'><i class='fa fa-times'></i>删除</a></div>");
					if(srm==""){
						srm=arg[i].src;
					}else{
						srm+=","+arg[i].src;
					}
		}
	
		if($("#mallimg").val()!=""){
			$("#mallimg").val($("#mallimg").val()+","+srm);
		}else{
			$("#mallimg").val(srm);
		}
	
	});
	 
	  o_ueditorupload.addListener('afterUpfile', function (t, arg) {
	    alert('这是文件地址：'+arg[0].url);
	  });
	});
	
        UE.getEditor('editor');
        //省市级联
        var province="${data.province}";
     	addressInit('province', 'city', 'county', '湖北', '襄樊市', '襄城区');
        if(province==""||province==null){//为空的话，默认给'湖北', '襄樊市', '襄城区'
            addressInit('Select1', 'Select2', 'Select3');
        }
    
        $("#province").val('${data.province}').change();
        $("#city").val('${data.city}').change();
        $("#county").val('${data.county}').change();
        form = $("form").Validform({
            tiptype: function (msg, o, cssctl) {
                //msg：提示信息;
                //o:{obj:*,type:*,curform:*}, obj指向的是当前验证的表单元素（或表单对象），type指示提示的状态，值为1、2、3、4， 1：正在检测/提交数据，2：通过验证，3：验证失败，4：提示ignore状态, curform为当前form对象;
                //cssctl:内置的提示信息样式控制函数，该函数需传入两个参数：显示提示信息的对象 和 当前提示的状态（既形参o中的type）;
                if (!o.obj.is("form")) {//验证表单元素时o.obj为该表单元素，全部验证通过提交表单时o.obj为该表单对象;
                    var objtip = o.obj.siblings(".Validform_checktip");
                    cssctl(objtip, o.type);
                    objtip.text(msg);
                } else {
                    var objtip = o.obj.find("#msgdemo");
                    cssctl(objtip, o.type);
                    objtip.text(msg);
                }
            },
            postonce: true,
            showAllError: true,
            callback: function () {
                save();
            }
        });

      //  
  
    });
    function save() {
     	var name= $("#name").val();
        var tel=$("#tel").val();
        var address=$("#address").val();
        
         if(name==""){
         	alert("店名不能为空")
         	$("#name").focus();
         	return ;
         }
        if(tel==""){
         	alert("电话不能为空")
         	$("#tel").focus();
         	return ;
         }
        if(address==""){
         	alert("地址不能为空")
         	$("#address").focus();
         	return ;
         }
        var context = UE.getEditor('editor').getContent();
        /* if (!/[\w\W]+/.test(context)) {
             alert("内容不能为空");
             return;
         }*/
        $("#context").val(context);       
        
	   //form提交 
	   ajaxFileUpload(function () {
           App.ajax(_path + "/mall/save", $("form").serialize(), function (data) {
               if (data.statusCode == 200) {
               App.bubble(200, "更新成功！");
            //  alert("更新成功")
                   window.setTimeout(function(){
                       window.location.href = _path + "/mall/list";
                   },400); 
               } else {
                  App.bubble(500, "信息失败！");
                     // alert("信息失败")
               }
           });
       });
    }
    //上传图片里面逻辑
    function ajaxFileUpload(callback) {
        if (!$("#file").val()&&!$("#filehd").val()) {
            callback();
            return;
        }else if($("#file").val()){
        	
        	   $.ajaxFileUpload({
                   url: '${path}/conf/upload',
                   secureuri: false,
                   fileElementId: 'file',
                   dataType: 'json',
                   success: function (data, status) {
                       switch (data.statusCode) {
                           case 200 :
                               $("#logo").val(data.uri);
                               if($("#filehd").val()){  //如果活动图有改变， 更改。
		                              $.ajaxFileUpload({
		                                   url: '${path}/conf/upload',
		                                   secureuri: false,
		                                   fileElementId: 'filehd',
		                                   dataType: 'json',
		                                   success: function (data, status) {
		                                       switch (data.statusCode) {
		                                           case 200 :
		                                               $("#by1").val(data.uri);
		                       		                   callback();
		                       		                break;
		                                           case 500 :
		                                        	   alert(data.info);
		                                               break;
		                                       }
		                                   }
		                               })
		                          	 break;
                             	  }else{
                             		 callback();
                             		 break;
                             	  }
	                         
                           case 500 :
                               alert(data.info);
                               break;
                       }
                   }
               });
        }else if($("#filehd").val()){
     	   $.ajaxFileUpload({
               url: '${path}/conf/upload',
               secureuri: false,
               fileElementId: 'filehd',
               dataType: 'json',
               success: function (data, status) {
                   switch (data.statusCode) {
                       case 200 :
                           $("#by1").val(data.uri);
   		                   callback();
                           break;
                       case 500 :
                           alert(data.info);
                           break;
                   }
               }
           });
        }else{
            return false;
        }
     
    }

    
    

    
  //弹出图片上传的对话框
    function upImage(){
     var myImage = o_ueditorupload.getDialog("insertimage");
      myImage.open();
    }
    //弹出文件上传的对话框
    function upFiles(){
    	  var myFiles = o_ueditorupload.getDialog("attachment");
      myFiles.open();
    } 
    /**
     * 删除店介绍图片
     */
    function   dels(em) {
    	 var uel=$(em).attr("el"); 
    	  $(".imgs").each(function(){
    		  if($(this).attr("sr")==uel){
    			  $(this).hide();
    		  }
    	  });
    
    	  var start = $("#mallimg").val();
    	  start = start.replace(uel,"");
    	 var arr= start.split(",");
    	  var newStart="";
    	  for(var i in arr){
    		  if(arr[i]!=""){
    				if(newStart==""){
    					newStart=arr[i];
					}else{
						newStart+=","+arr[i];
					}
    		  }
    	  }
     	  $("#mallimg").val(newStart)
     	 
    	  $(em).hide();
    }
    /**
     * 删除编辑默认图片
     */
    function delpic(id){
    	$("#"+id).val("");
    	$("."+id).attr("src","");
    }
    
 function   opemrte(em){
	 if($(em).val()==2){
		 $("#dkea").hide();
	 }else{
		 $("#dkea").show();
	 }
 }
</script>

</body>
</html>